package com.bright.hxj.cwduijie.service.impl;

import com.bright.hxj.cwduijie.enums.DataApi;
import com.bright.hxj.cwduijie.pojo.bo.ApiDataCollection;
import com.bright.hxj.cwduijie.pojo.po.ExpenseDetail;
import com.bright.hxj.cwduijie.pojo.query.DuijieQuery;
import com.bright.hxj.cwduijie.repository.ExpenseDetailRepository;
import com.bright.hxj.cwduijie.service.AbstractMonthlyReportApiService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

/**
 * @Author hxj
 * @Date 2025/2/21 16:05
 * @Description
 */
@Component
@RequiredArgsConstructor
public class ApiExpenseDetailServiceImpl extends AbstractMonthlyReportApiService<ExpenseDetail, ExpenseDetail> {

    private final ExpenseDetailRepository repo;

    @Override
    protected void getData(ApiDataCollection apiDataCollection, DuijieQuery duijieQuery) {
        apiDataCollection.setExpenseDetailMap(Collections.singletonMap("", getNeedDuijieData(duijieQuery)));
    }

    @Override
    public JpaSpecificationExecutor getJpaSpecificationExecutor() {
        return repo;
    }

    @Override
    public DataApi getDataApi() {
        return DataApi.EXPENSE_DETAIL;
    }

    @Override
    public Function<ExpenseDetail, Integer> getIdFunc() {
        return ExpenseDetail::getId;
    }

    @Override
    public Function<ApiDataCollection, Map<String, List<ExpenseDetail>>> getDataFunc() {
        return ApiDataCollection::getExpenseDetailMap;
    }

    @Override
    public Function<ExpenseDetail, ExpenseDetail> getConverterFunc() {
        return Function.identity();
    }
}
